'use strict';

const BaseController = require('../base');

class UserPostLikeController extends BaseController {
    static get serviceName() {
        return 'business.userPostLike';
    }

    /**
     * 点赞动态
     */
    async like() {
        const { id } = this.ctx.params; // post_id
        const { user_id } = this.ctx.request.body;

        if (!user_id) {
            throw new Error('用户ID不能为空');
        }

        const result = await this.ctx.service.business.userPostLike.like(id, user_id);
        this.ctx.success(result);
    }

    /**
     * 取消点赞
     */
    async unlike() {
        const { id } = this.ctx.params; // post_id
        const { user_id } = this.ctx.request.body;

        if (!user_id) {
            throw new Error('用户ID不能为空');
        }

        const result = await this.ctx.service.business.userPostLike.unlike(id, user_id);
        this.ctx.success(result);
    }
}

module.exports = UserPostLikeController; 